﻿
using System;
using System.Linq;
using System.Data;
using System.Collections;
using System.Collections.ObjectModel;
using System.Threading;

namespace NMbsDuplex.TCPServerX.Node
{
    using System.Collections.Generic;
    using System.Net.Sockets;
    using MrPoetic.MatLab.Hash;

    public class NodesUser
    {
        // 持久数据
        protected internal readonly Socket refSock;
        protected internal readonly DateTime RegisterDate;
        public readonly string UserName;
        readonly string password;
        // 动态数据
        public bool isDone = false;
        public DateTime LastLoginTime;
        public List<string> MsgLogs = new List<string>();

        public NodesUser(Socket refSockFD)
        {
            RegisterDate = DateTime.Parse("2017-11-24");
            UserName = Guid.NewGuid().ToString();
            LastLoginTime = DateTime.Now;
            refSock = refSockFD;
            /* 
             * 首次登入加载持久数据 如果发现GUID过期 
             * 则根据 OAuth2.0协议更新Token
             * 系统默认初始化密码 123456
             */
            password = "123456".ToHashString();
        }

        public override string ToString()
        {
            var s = string.Format("用户[{0}]于格林威治时间{1}登录系统...", 
                refSock.RemoteEndPoint, LastLoginTime.ToString("D"));
            Console.WriteLine(password);
            return s;
        }
    }
}
